package com.example.permissionserviceconsumer.service;

import com.myprojects.common.pojo.Resource;
import com.myprojects.common.pojo.ResourceParent;
import com.myprojects.common.dto.Msg;
import com.myprojects.common.pojo.UserWithRole;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Component
public class FeignPermissionServiceFallback implements FeignPermissionService{

    /**
     * 该方法用于通过用户token来查询用户信息(权限)
     */
    @Override
    public Msg getUserByToken(String accessToke){
        Msg msg = Msg.failed();
        Resource resource = new Resource();
        resource.setId(-1);
        resource.setResource_name("提供者无响应!");
        resource.setResource("/nothing");
        ResourceParent parent = new ResourceParent();
        List<ResourceParent> resourceParentList = new ArrayList<>();
        parent.setTitle("提供者无响应!");
        for (int i = 0; i < 3; i++) {
            parent.addResource(resource);
        }
        resourceParentList.add(parent);
        UserWithRole user = new UserWithRole();
        user.setUsername("用户接口无响应");
        user.setNickname("用户接口无响应");
        user.setResourceParentList(resourceParentList);
        msg.setMsg("查询权限接口无响应!");
        msg.addData("user",user);
        return msg;
    }

    @Override
    public boolean checkUserRequest(String accessToken, String requestURI) {
        return false;
    }

}
